package com.sfx.concurrent.demo.concurrent.AtomicTest.Atomic;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-19
 * Time: 17:10
 */
public class AtomicReferenceUpdater {

    public static void main(String[] args) {
        Student student = new Student();
        AtomicReferenceFieldUpdater fieldUpdater = //为哪一个类,属性类型,属性
                AtomicReferenceFieldUpdater.newUpdater(Student.class,String.class,"name");
        System.out.println(fieldUpdater.compareAndSet(student, null, "zhangsan"));
        System.out.println(student);
    }

}
class Student {
    public volatile String name;
    public int age;

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
